package com.example.shop.fgo.utils;

/**
 * Created by Administrator on 2017/2/11.
 */

public class SizeUtil {
    public static final int MB=1024*1024;
    public static final int KB=1024;
    public static String formatSize(long sizeBytes){
        Long m=sizeBytes/MB;
        String dw=null;
        String temp=null;
        if (m>=1) {
            dw="MB";
             temp=String.valueOf(sizeBytes*1.0f/MB);

        }else{
            dw="K";
              temp=String.valueOf(sizeBytes*1.0f/KB);
        }
        temp.indexOf(".");
        int tempLength=temp.length();
        int pointerPos=temp.indexOf(".");
        int subPos=pointerPos+3;
        if (subPos<tempLength) {
            temp=temp.substring(0,subPos);
        }
        return temp+dw;
    }
    public static String formatSpeed(long sizeBytes){
        Long m=sizeBytes/MB;
        String dw=null;
        String temp=null;
        if (m>=1) {
            dw="MB/s";
            temp=String.valueOf(sizeBytes*1.0f/MB);

        }else{
            dw="K/s";
            temp=String.valueOf(sizeBytes*1.0f/KB);
        }
        temp.indexOf(".");
        int tempLength=temp.length();
        int pointerPos=temp.indexOf(".");
        int subPos=pointerPos+3;
        if (subPos<tempLength) {
            temp=temp.substring(0,subPos);
        }
        return temp+dw;
    }
}
